class Node:
    def __init__(self):
        self.data = None
        self.next = None
        self.prev = None

class LIFO:
    def __init__(self):
        self.head = Node()
        self.tail = Node()
        self.length = 0
        self.head.next = self.tail
        self.tail.prev = self.head

    def push(self, data):
        newNode = Node()
        newNode.data = data
        pnode = self.tail.prev
        newNode.prev = pnode
        newNode.next = self.tail
        pnode.next = newNode
        self.tail.prev = newNode
        self.length += 1

    def pop(self):
        assert self.length != 0
        pnode = self.tail.prev
        pnode.prev.next = self.tail
        self.tail.prev = pnode.prev
        self.length -= 1

    def __iter__(self):
        node = self.head.next
        while node != self.tail:
            yield node.data
            node = node.next


if __name__ == '__main__':

    l = LIFO()

    for i in range(1,10):
        l.push(i)

    l.pop()

    for i in l:
        print(i)
